<template>
  <div class="filter-container">
    <el-input
      v-model="queryParam.dictName"
      label="字典名称"
      placeholder="请输入字典名称"
      class="filter-item search-item"
    />
    <el-input
      v-model="queryParam.dictType"
      label="字典编号"
      placeholder="请输入字典类型"
      class="filter-item search-item"
    />
    <el-button class="filter-item" type="primary" plain @click="search">
      {{ $t('table.search') }}
    </el-button>
    <el-button class="filter-item" type="warning" plain @click="reset">
      {{ $t('table.reset') }}
    </el-button>
    <el-dropdown v-has-any-permission="['dict:add']" trigger="click" class="filter-item">
      <el-button>
        {{ $t('table.more') }}<i class="el-icon-arrow-down el-icon--right" />
      </el-button>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item v-has-permission="['dict:add']" @click.native="add">{{ $t('table.add') }}</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
export default {
  name: 'IndexFilter',
  data() {
    return {
      queryParam: {}
    }
  },
  methods: {
    search() {
      for (const key in this.queryParam) {
        if (this.queryParam[key] === '') {
          delete this.queryParam[key]
        }
      }
      this.$emit('search', this.queryParam)
    },
    reset() {
      this.queryParam = {}
      this.$emit('search', this.queryParam)
    },
    add() {
      this.$emit('add')
    }
  }
}
</script>

<style lang="scss" scoped>
  .filter-container .search-item{
    width: 150px;
  }
</style>
